<?php

namespace App\Admin\Controllers;

use App\Models\Teacher;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class TeacherController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '教师';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Teacher());

        $grid->column('id', 'ID');
        $grid->column('name', '教师姓名');
        $grid->column('gender', '性别')->display(function ($gender) {
            return Teacher::$genders[$gender];
        });
        $grid->column('department', '部门');
        $grid->column('email', '邮箱');
        $grid->column('phone', '手机号');
        $grid->column('created_at', '创建时间');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Teacher::findOrFail($id));

        $show->field('id', 'ID');
        $show->field('name', '教师姓名');
        $show->field('gender', '性别');
        $show->field('department', '部门');
        $show->field('email', '邮箱');
        $show->field('phone', '手机号');
        $show->field('created_at', '创建时间');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Teacher());

        $form->text('name', '教师姓名');
//        $form->text('gender', '性别');
        $form->radio('gender', '性别')->options(Teacher::$genders);
        $form->text('department', '部门');
        $form->email('email', '邮箱');
        $form->mobile('phone', '手机号');

        return $form;
    }
}
